<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Symbol在缓存容器中的使用</title>
</head>
<body>
    <script>
        class Cache{
            static data = {};
            static set(name,value) {
                return (this.data[name] = value);
            }

            static get(name){
                return this.data[name];
            }
        }

        // Cache.set("xiasnn",'大美女');
        // console.log(Cache.get("xiasnn"));


        let user = {
            name : "apple",
            desc : "用户"
        };

        let cart = {
            name : "apple",
            desc : "购物车"
        };

        // Cache.set("apple",user);
        // Cache.set("apple",cart);
        // console.log(Cache.get("apple"));    //只能得到最后一个


        // 没有Symbol这样取
        Cache.set("user-apple",user);
        Cache.set("cart-apple",cart);
        console.log(Cache.get("user-apple"));
        console.log(Cache.get("cart-apple"));




        // 有symbol的情况
        let user1 = {
            name : "apple",
            desc : "用户",
            key : Symbol("用户资料")
        };

        let cart1 = {
            name : "apple",
            desc : "购物车",
            key : Symbol("购物车资料")
        };
        Cache.set(user1.key,user1);
        Cache.set(cart1.key,cart1);
        console.log(Cache.get(user1.key));
        console.log(Cache.get(cart1.key));

    </script>
</body>
</html>